use "~/Desktop/QJPS Replication/Table_1.dta", clear 

tsset cow year 
gen abs_diff = abs(cscore - l.cscore)

*new variable for changes to the constitution - group new, provisional, and reinstate
gen change = .
replace change = 0 if evnttype == 4 //no change
replace change = 1 if evnttype == 1 //amendment
replace change = 2 if evnttype == 2 | evnttype == 3 | evnttype == 5 //new constitution

*greate a lagged variable for resumption of order in the last 2 years
gen resume2 = .
replace resume2 = 0 if resume_order == 0 & l.resume_order == 0
replace resume2 = 1 if resume_order == 1
replace resume2 = 1 if l.resume_order == 1

*greate a lagged variable for stop of order in the last 2 years
gen stop2 = .
replace stop2 = 0 if stop_order == 0 & l.stop_order == 0
replace stop2 = 1 if stop_order == 1
replace stop2 = 1 if l.stop_order == 1

*greate a lagged variable for transition to democracy in the last 2 years
gen transdemoc2 = .
replace transdemoc2 = 0 if trans_to_democracy == 0 & l.trans_to_democracy == 0
replace transdemoc2 = 1 if trans_to_democracy == 1
replace transdemoc2 = 1 if l.trans_to_democracy == 1

*greate a lagged variable for transition from democracy in the last 2 years
gen transawaydemoc2 = .
replace transawaydemoc2 = 0 if away_from_democracy == 0 & l.away_from_democracy == 0
replace transawaydemoc2 = 1 if away_from_democracy == 1
replace transawaydemoc2 = 1 if l.away_from_democracy == 1

*greate a lagged variable for resumption of order in the last 3 years
gen resume3 = .
replace resume3 = 0 if resume_order == 0 & l.resume_order == 0 & l2.resume_order == 0
replace resume3 = 1 if resume_order == 1
replace resume3 = 1 if l.resume_order == 1
replace resume3 = 1 if l2.resume_order == 1

*greate a lagged variable for stop of order in the last 3 years
gen stop3 = .
replace stop3 = 0 if stop_order == 0 & l.stop_order == 0 & l2.stop_order == 0
replace stop3 = 1 if stop_order == 1
replace stop3 = 1 if l.stop_order == 1
replace stop3 = 1 if l2.stop_order == 1

*greate a lagged variable for transition to democracy in the last 3 years
gen transdemoc3 = .
replace transdemoc3 = 0 if trans_to_democracy == 0 & l.trans_to_democracy == 0 & l2.trans_to_democracy == 0
replace transdemoc3 = 1 if trans_to_democracy == 1
replace transdemoc3 = 1 if l.trans_to_democracy == 1
replace transdemoc3 = 1 if l2.trans_to_democracy == 1

*greate a lagged variable for transition from democracy in the last 3 years
gen transawaydemoc3 = .
replace transawaydemoc3 = 0 if away_from_democracy == 0 & l.away_from_democracy == 0 & l2.away_from_democracy == 0
replace transawaydemoc3 = 1 if away_from_democracy == 1
replace transawaydemoc3 = 1 if l.away_from_democracy == 1
replace transawaydemoc3 = 1 if l2.away_from_democracy == 1


*regress changes on changes to societal order
areg abs_diff i.year i.change, absorb(cow) vce(cluster cow)
areg abs_diff i.year stop_order resume_order trans_to_democ away_from_democracy, vce(cluster cow) absorb(cow)
areg abs_diff i.year stop2 resume2  transdemoc2 transawaydemoc2, vce(cluster cow) absorb(cow)
areg abs_diff i.year stop3 resume3  transdemoc3 transawaydemoc3 if year > 1824, vce(cluster cow) absorb(cow)







